package com.hoshiibuy.company.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hoshiibuy.common.rpc.Response;
import com.hoshiibuy.company.service.IComOrganizationService;
import com.hoshiibuy.company.entity.ComOrganization;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 机构表 前端控制器
 * </p>
 *
 * @author WGJ
 * @since 2019-04-22
 */
@RestController
@RequestMapping("/companyOrg")
@Api(value = "机构管理", tags = {"机构操作接口"})
public class ComOrganizationController {
    private final Logger LOGGER = LoggerFactory.getLogger(ComOrganizationController.class);

    @Autowired
    IComOrganizationService comOrgService;

    @RequestMapping(value = "/upComOrgById", method = RequestMethod.POST)
    @ApiOperation(
            value = "修改",
            notes = "根据id修改采购商信息",
            produces = "application/json, application/xml",
            consumes = "application/json, application/xml")
    public Response upComOrgById(@Valid ComOrganization comOrganization) {
        return Response.data(comOrgService.updateById(comOrganization));
    }

    @RequestMapping(value = "/findComOrgById", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询",
            notes = "根据id采购商信息",
            produces = "application/json, application/xml",
            consumes = "application/json, application/xml")

    public Response findComOrgById(Long id) {

        return Response.data(comOrgService.getById(id));
    }

    @RequestMapping(value = "/findComOrgByName", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询",
            notes = "根据名称采购商信息",
            produces = "application/json, application/xml",
            consumes = "application/json, application/xml")
    public Response findComOrgByName(String name) {
        Wrapper wrapper = Wrappers.<ComOrganization>query().lambda().eq(ComOrganization::getName, name);
        return Response.data(comOrgService.getOne(wrapper));
    }

}
